package com.food.user.controller;


import com.food.user.commos.Result;
import com.food.user.dto.EsFoodDto;
import com.food.user.exception.MyParameterException;
import com.food.user.form.EsFoodForm;
import com.food.user.form.UserAccountRegisterForm;
import com.food.user.service.FoodInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 菜品 前端控制器
 * </p>
 *
 * @author 帅得一
 * @since 2023年06月17日
 */
@RestController
@RequestMapping("/foodInfo")
@Api(tags = "食品接口")
public class FoodInfoController {
    @Autowired
    private FoodInfoService foodInfoService;

    @GetMapping("/list")
    @ApiOperation("es查询食品")
    public Result register(EsFoodForm form, BindingResult br) throws Exception{
        if (br.hasErrors()) {
            List<ObjectError> allErrors = br.getAllErrors();
            for (ObjectError allError : allErrors) {
                //获取打印提示信息
                System.out.println(allError.getDefaultMessage());
            }
            throw new MyParameterException(500, "参数校验失败");
        }
        EsFoodDto foodDto=foodInfoService.esList(form);
        return Result.success(200,"es查询食品成功",foodDto);
    }

}

